﻿using Salient.Util;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Drawing;
namespace EnumDataSourceTests
{

    [TestClass()]
    public class EnumExtensionsTest
    {
        /// <summary>
        ///A test for GetDescription
        ///</summary>
        [TestMethod()]
        public void GetDescriptionTest()
        {
            Enum value = Salient.Util.TestEnum01.valueone;
            string expected = "Value One";
            string actual;
            actual = EnumExtensions.GetDescription(value);
            Assert.AreEqual(expected, actual);

        }

        /// <summary>
        ///A test for GetEnumType
        ///<para>in test does not resolve enum types that are not in mscorlib?? e.g. System.IO.FileAttribute resolves while System.Color.KnownColor does not</para>
        ///</summary>
        [TestMethod()]
        public void GetEnumTypeTest()
        {
            string enumTypeFullName = "Salient.Util.TestEnum01";
            Type expected = typeof(Salient.Util.TestEnum01);
            Type actual;
            actual = EnumExtensions.GetEnumType(enumTypeFullName);
            Assert.AreEqual(expected, actual);

        }

        /// <summary>
        ///A test for GetTypedValue
        ///</summary>
        [TestMethod()]
        public void GetTypedValueTest()
        {
            Enum value = System.IO.FileAttributes.Device;
            object expected = (int)System.IO.FileAttributes.Device;
            object actual;
            actual = EnumExtensions.GetTypedValue(value);
            Assert.AreEqual(expected, actual);

        }

        /// <summary>
        ///A test for GetTypedValue Flags
        ///</summary>
        [TestMethod()]
        public void GetTypedValueTestFlags()
        {
            Enum value = TestEnumFlags01.valueone | TestEnumFlags01.valuefour;
            object expected = (int)5;
            object actual;
            actual = EnumExtensions.GetTypedValue(value);
            Assert.AreEqual(expected, actual);

        }

        /// <summary>
        ///A test for GetValue scalar
        ///</summary>
        [TestMethod()]
        public void GetValueTest()
        {
            Type enumType = typeof(System.IO.FileAttributes);
            string description = "Device";
            Enum expected = System.IO.FileAttributes.Device;
            Enum actual;
            actual = EnumExtensions.GetValue(enumType, description);
            Assert.AreEqual(expected, actual);

        }

        //    public enum TestEnum01
        //    {
        //        [Description("Value One")]
        //        valueone,
        //        valuetwo,
        //        [Description("Value Three")]
        //        valuethree
        //    }

        /// <summary>
        ///A test for GetValue with description
        ///</summary>
        [TestMethod()]
        public void GetValueTestDescription()
        {
            Type enumType = typeof(Salient.Util.TestEnum01);
            string description = "Value One";
            Enum expected = Salient.Util.TestEnum01.valueone;
            Enum actual;
            actual = EnumExtensions.GetValue(enumType, description);
            Assert.AreEqual(expected, actual);

        }

        //    [Flags]
        //    public enum TestEnumFlags01
        //    {
        //        [Description("Value One")]
        //        valueone=1,
        //        valuetwo=2,
        //        [Description("Value Four")]
        //        valuefour=4
        //    }

        /// <summary>
        ///A test for GetValue with description Flags
        ///</summary>
        [TestMethod()]
        public void GetValueTestDescriptionFlags()
        {
            Type enumType = typeof(Salient.Util.TestEnumFlags01);
            string description = "Value One,  valuetwo";
            Enum expected = Salient.Util.TestEnumFlags01.valueone | Salient.Util.TestEnumFlags01.valuetwo;
            Enum actual;
            actual = EnumExtensions.GetValue(enumType, description);
            Assert.AreEqual(expected, actual);

        }

        //    [Flags]
        //    public enum TestEnumFlags01
        //    {
        //        [Description("Value One")]
        //        valueone=1,
        //        valuetwo=2,
        //        [Description("Value Four")]
        //        valuefour=4
        //    }

        /// <summary>
        ///A test for GetValue with description Flags
        ///</summary>
        [TestMethod()]
        public void GetValueTestDescriptionFlagsLoose()
        {
            string enumTypeFullName = "Salient.Util.TestEnumFlags01";
            string description = "Value One,  valuetwo";
            Enum expected = Salient.Util.TestEnumFlags01.valueone | Salient.Util.TestEnumFlags01.valuetwo;
            Enum actual;
            actual = EnumExtensions.GetValue(enumTypeFullName, description);
            Assert.AreEqual(expected, actual);

        }

        //    public enum TestEnum01
        //    {
        //        [Description("Value One")]
        //        valueone,
        //        valuetwo,
        //        [Description("Value Three")]
        //        valuethree
        //    }

        /// <summary>
        ///A test for GetValue with description
        ///</summary>
        [TestMethod()]
        public void GetValueTestDescriptionLoose()
        {
            string enumTypeFullName = "Salient.Util.TestEnum01";
            string description = "Value One";
            Enum expected = Salient.Util.TestEnum01.valueone;
            Enum actual;
            actual = EnumExtensions.GetValue(enumTypeFullName, description);
            Assert.AreEqual(expected, actual);

        }

        //	[Flags]
        //	public enum FileAttributes
        //	{
        //	    Archive = 0x20,
        //	    Compressed = 0x800,
        //	    Device = 0x40,
        //	    Directory = 0x10,
        //	    Encrypted = 0x4000,
        //	    Hidden = 2,
        //	    Normal = 0x80,
        //	    NotContentIndexed = 0x2000,
        //	    Offline = 0x1000,
        //	    ReadOnly = 1,
        //	    ReparsePoint = 0x400,
        //	    SparseFile = 0x200,
        //	    System = 4,
        //	    Temporary = 0x100
        //	}
        /// <summary>
        ///A test for GetValue Flags
        ///</summary>
        [TestMethod()]
        public void GetValueTestFlags()
        {
            Type enumType = typeof(System.IO.FileAttributes);
            string description = "Archive, Compressed";
            Enum expected = System.IO.FileAttributes.Archive | System.IO.FileAttributes.Compressed;
            Enum actual;
            actual = EnumExtensions.GetValue(enumType, description);
            Assert.AreEqual(expected, actual);

        }

        //	[Flags]
        //	public enum FileAttributes
        //	{
        //	    Archive = 0x20,
        //	    Compressed = 0x800,
        //	    Device = 0x40,
        //	    Directory = 0x10,
        //	    Encrypted = 0x4000,
        //	    Hidden = 2,
        //	    Normal = 0x80,
        //	    NotContentIndexed = 0x2000,
        //	    Offline = 0x1000,
        //	    ReadOnly = 1,
        //	    ReparsePoint = 0x400,
        //	    SparseFile = 0x200,
        //	    System = 4,
        //	    Temporary = 0x100
        //	}
        /// <summary>
        ///A test for GetValue Flags
        ///</summary>
        [TestMethod()]
        public void GetValueTestFlagsLoose()
        {
            string enumTypeFullName = "System.IO.FileAttributes";
            string description = "Archive, Compressed";
            Enum expected = System.IO.FileAttributes.Archive | System.IO.FileAttributes.Compressed;
            Enum actual;
            actual = EnumExtensions.GetValue(enumTypeFullName, description);
            Assert.AreEqual(expected, actual);

        }

        /// <summary>
        ///A test for GetValue scalar
        ///</summary>
        ///<remarks>
        ///<para></para>
        /// </remarks>
        [TestMethod()]
        public void GetValueTestLoose()
        {


            string enumTypeFullName = "System.IO.FileAttributes";

            string description = "Device";
            Enum expected = System.IO.FileAttributes.Device;
            Enum actual;
            actual = EnumExtensions.GetValue(enumTypeFullName, description);
            Assert.AreEqual(expected, actual);

        }
 

    }
}
